<template>
	<view class="container">
    <u-toast ref="uToast"></u-toast>
		<u-picker :show="show" :columns="columns" :title="title" @cancel="show=false" @confirm="confirm"></u-picker>
<!--		<u-calendar :show="showCalendar" :mode="mode" @confirm="calendarConfirm" @close="showCalendar=false">-->
<!--		</u-calendar>-->
    <u-datetime-picker
        :show="showCalendar"
        mode="date"
        @confirm="calendarConfirm"
    ></u-datetime-picker>
		<view>
			<u--form labelPosition="left" :model="from" :rules="rules" ref="form1" labelWidth='100px'
				:labelStyle='labelStyle'>
				<view class="box">
					<u-form-item label="生产装置套数" prop="sczzts" borderBottom>
						<u--input v-model="from.sczzts" placeholder="填写生产装置套数" border="none"></u--input>
					</u-form-item>
					<u-form-item label="运行套数" prop="yxts" borderBottom>
						<u--input v-model="from.yxts" placeholder="填写运行套数" border="none"></u--input>
					</u-form-item>
					<u-form-item label="停车套数" prop="tcts" borderBottom>
						<u--input v-model="from.tcts" placeholder="填写停车套数" border="none"></u--input>
					</u-form-item>
					<u-form-item label="断路作业" prop="dlzy" borderBottom>
						<u--input v-model="from.dlzy" placeholder="填写数量" border="none"></u--input>
					</u-form-item>
					<u-form-item label="动土作业" prop="dtzy" borderBottom>
						<u--input v-model="from.dtzy" placeholder="填写数量" border="none"></u--input>
					</u-form-item>
					<u-form-item label="高处作业" prop="gczy" borderBottom>
						<u--input v-model="from.gczy" placeholder="填写数量" border="none"></u--input>
					</u-form-item>
					<u-form-item label="临时用电作业" prop="lsydzy" borderBottom>
						<u--input v-model="from.lsydzy" placeholder="填写数量" border="none"></u--input>
					</u-form-item>
					<u-form-item label="吊装作业" prop="dzzy" borderBottom>
						<u--input v-model="from.dzzy" placeholder="填写数量" border="none"></u--input>
					</u-form-item>
					<u-form-item label="盲板作业" prop="mbzy" borderBottom>
						<u--input v-model="from.mbzy" placeholder="填写数量" border="none"></u--input>
					</u-form-item>
					<u-form-item label="二级动火作业" prop="ejdhzy" borderBottom>
						<u--input v-model="from.ejdhzy" placeholder="填写数量" border="none"></u--input>
					</u-form-item>
					<u-form-item label="一级动火作业" prop="yjdhzy" borderBottom>
						<u--input v-model="from.yjdhzy" placeholder="填写数量" border="none"></u--input>
					</u-form-item>
					<u-form-item label="受限空间作业" prop="sxkjzy" borderBottom>
						<u--input v-model="from.sxkjzy" placeholder="填写数量" border="none"></u--input>
					</u-form-item>
					<u-form-item label="检维修作业" prop="jwxzy" borderBottom>
						<u--input v-model="from.jwxzy" placeholder="填写数量" border="none"></u--input>
					</u-form-item>
					<u-form-item label="特殊动火作业" prop="tjdhzy" borderBottom>
						<u--input v-model="from.tjdhzy" placeholder="填写数量" border="none"></u--input>
					</u-form-item>
					<u-form-item label="承包商作业" prop="contractorJob" borderBottom
						@click="italic('contractorJob','是否承包商作业')">
						<u--input v-model="from.contractorJob" disabled disabledColor="#ffffff" placeholder="是否承包商作业"
							border="none"></u--input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>
					<u-form-item label="试生产期" prop="probation" borderBottom @click="italic('probation','是否试生产期')">
						<u--input v-model="from.probation" disabled disabledColor="#ffffff" placeholder="是否处于试生产期"
							border="none"></u--input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>
					<u-form-item label="开停车状态" prop="parkingStatus" borderBottom
						@click="italic('parkingStatus','是否处于开停车状态')">
						<u--input v-model="from.parkingStatus" disabled disabledColor="#ffffff" placeholder="是否处于开停车状态"
							border="none"></u--input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>
					<u-form-item label="中（扩）试" prop="expand" borderBottom @click="italic('expand','是否开展中(扩)试')">
						<u--input v-model="from.expand" disabled disabledColor="#ffffff" placeholder="是否开展中(扩)试"
							border="none"></u--input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>
					<u-form-item label="重大隐患" prop="majorHiddenDanger" borderBottom
						@click="italic('majorHiddenDanger','是否有重大隐患')">
						<u--input v-model="from.majorHiddenDanger" disabled disabledColor="#ffffff"
							placeholder="是否有重大隐患" border="none"></u--input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>
					<u-form-item label="风险级别" prop="riskLevel" borderBottom @click="italic('riskLevel','风险级别')">
						<u--input v-model="from.riskLevel" disabled disabledColor="#ffffff" placeholder="请选择风险级别"
							border="none"></u--input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>
					<u-form-item label="承诺日期" prop="cnrq" borderBottom @click="showCalendar=true">
						<u--input v-model="from.cnrq2" disabled disabledColor="#ffffff" placeholder="请选择承诺日期"
							border="none"></u--input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>
					<user-pick :label="'承诺人'" :multiple="false" :title="'承诺人'" :placeholder="'选择承诺人'"
						v-model="from.cnr" :prop="'cnr'"></user-pick>
					<u-form-item label="研判级别" prop="judgmentLevel" borderBottom
						@click="italic('judgmentLevel','请选择研判级别')">
						<u--input v-model="from.judgmentLevel" disabled disabledColor="#ffffff" placeholder="请选择研判级别"
							border="none"></u--input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>
				</view>
			</u--form>
			<u-button type="primary" text="提交" @click="submit" class='but'></u-button>
		</view>
	</view>
</template>

<script>
	import {AdddailyJudgmentAPI} from '@/api/api.js'
	import userPick from "@/pages/Components/userPick";
	export default {
		components: {
			userPick,
		},
		data() {
			return {
				labelStyle: {
					color: '#666'
				},
				title: '',
				showCalendar: false,
				mode: 'range',
				columns: [
					[]
				],
				from: {
					text: '',
          cnr:'',
          cnrq2:null
				},
				optionsList: {
					'contractorJob': ['否', '是'],
					'probation': ['否', '是'],
					'parkingStatus': ['否', '是'],
					'expand': ['否', '是'],
					'majorHiddenDanger': ['否', '是'],
					'riskLevel': ['高风险', '较大风险', '一般风险', '低风险'],
					'judgmentLevel': ['公司', '车间', '班组']
				},
				show: false,
				rules: {
					'tjdhzy': {
						type: 'string',
						required: true,
						message: '请填写特殊动火作业',
						trigger: ['blur', 'change']
					},
				},
			};
		},
		methods: {
			italic(name, title) {
				this.show = true
				this.title = title
				this.temKey = name
				this.columns = [this.optionsList[name]]
			},
			confirm(e) {
				switch (this.temKey) {
					case 'contractorJob':
						this.from.sfycbszy = e.indexs[0]
					case 'probation':
						this.from.sfcysscq = e.indexs[0]
					case 'parkingStatus':
						this.from.sfcyktczt = e.indexs[0]
					case 'expand':
						this.from.sfkzzks = e.indexs[0]
					case 'majorHiddenDanger':
						this.from.ywzdyh = e.indexs[0]
					case 'riskLevel':
						this.from.fxjb = e.indexs[0] + 1
					case 'judgmentLevel':
						this.from.ypjb = e.indexs[0] + 1
				}
				this.from[this.temKey] = e.value[0]
				this.show = false
			},
			calendarConfirm(e) {
				// this.from.cnrq = `${e[0]}~${e.pop()}`
        const timeFormat = uni.$u.timeFormat;
        this.from.cnrq = timeFormat(e.value, "yyyymmddhhMM");
        this.from.cnrq2 = timeFormat(e.value, "yyyy-mm-dd");
				this.showCalendar = false
			},
			submit() {
				AdddailyJudgmentAPI({
					...this.from
				}).then((r) => {
					if (r.code === 200) {
						this.$refs.uToast.show({
							type: 'success',
							message: "提交成功",
							iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/jump.png'
						})
						setTimeout((e) => {
							uni.navigateBack({
								delta: 1
							})
						}, 2000)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.container {
		padding: 24rpx;
		background-color: #f6f6f6;

		.title {
			font-size: 28rpx;
			font-weight: 500;
			color: #999999;
			line-height: 44rpx;
			padding: 20rpx 48rpx;
		}

		.box {
			padding: 0rpx 48rpx;
			background-color: #fff;
			border-radius: 20rpx;
		}
	}

	.but {
		margin: 30rpx 0;
	}
</style>
